﻿using Gengens.Disk.Service.service;
using Gengens.Disk.WebApi.dto.output;
using Microsoft.AspNetCore.Mvc;

namespace Gengens.Disk.WebApi.Controllers.file
{
    public class DataInfoController : BaseUserController
    {

        private readonly DataInfoService _dataInfoService;

        public DataInfoController(DataInfoService dataInfoService)
        {
            _dataInfoService = dataInfoService;
        }


        #region 查询

        [HttpGet]
        public async Task<ApiRet> AllData()
        {
            var data = await _dataInfoService.SelectAsync(s => s.UserId == UserId);
            return ApiRet.Ok("查询成功", data);
        }

        [HttpGet("{id}")]
        public async Task<ApiRet> GetById([FromRoute] Guid id)
        {
            var data = await _dataInfoService.FindAsync(id);
            return ApiRet.Ok("查询成功", data);
        }

        #endregion

        #region Delete

        [HttpDelete("{id}")]
        public async Task<ApiRet> Delete([FromRoute] Guid id)
        {
            var data = await _dataInfoService.FindAsync(id);
            if (data == default) return ApiRet.Fail($"找不到id为{id}的资源");
            _dataInfoService.Delete(data);
            return ApiRet.Ok();
        }

        #endregion

    }
}
